const app = getApp()
const {
  envList
} = require('../../../envList.js')
var util = require('../../../utils/util.js');
Page({
  data: {
    identity_id: 1
  },
  onLoad: function (options) {
    wx.setStorageSync('identity_id', 1);
    this.setData({
      card_number: options.card_number || '2275021101',
      card_password: options.card_password || 'iKqRoiy0unpYCrO2',
      goods_name: options.goods_name || '',
      goods_type: options.goods_type || '',
      expiration_date: options.expiration_date || '',
      card_url: options.card_url || ''
    });
    this.getUserinfo(1);
  },
  // 获取用户信息
  getUserinfo(initial_id) {
    wx.showLoading({
      title: '系统正在处理',
    })
    wx.cloud.callFunction({
      name: "getUserInfo",
      data: {
        identity_id: this.data.identity_id,
        initial_id: initial_id
      },
      success: res => {
        wx.hideLoading();
        this.setData({
          powerList: res.result.list
        })
        // 缓存
        wx.setStorageSync('openid', res.result.openid);
        wx.setStorageSync('powerList', res.result.list);
      }
    })
  },
  // 前往提货信息页面
  toPicking(e) {
    wx.showLoading({
      title: '系统正在处理',
    })
    wx.cloud.callFunction({
      name: "judgeAccount",
      data: {
        card_number: this.data.card_number,
        card_password: this.data.card_password,
      },
      success: res => {
        wx.hideLoading();
        let list = res.result.list[0];
        console.log(list);
        if (res.result.list.length != 0) {
          wx.navigateTo({
            url: '/pages/customer/picking/picking?card_id=' + list._id + '&card_number=' + this.data.card_number + '&card_password=' + this.data.card_password + '&goods_url=' + list.goods_url + '&goods_name=' + list.goods_name + '&goods_id=' + list.goods_id + '&goods_number=' + list.goods_number + '&goods_explain=' + list.goods_explain + '&specs=' + list.specs + '&type=' + list.type,
          });
        } else {
          wx.showToast({
            title: '提货码无效',
            icon: 'error',
            duration: 2000
          })
        }
      }
    })
  },
  // 领取到卡包
  toCardBag(){
    wx.showToast({
      title: '暂不支持',
      icon: 'error'
    })
  },
  // 复制信息到粘贴板
  copyData(e) {
    wx.setClipboardData({
      data: e.currentTarget.dataset.info,
      success() {
        wx.showToast({
          title: '复制成功',
          icon: 'success',
          duration: 2000
        })
      }
    })
  },
})